#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
using namespace std;
class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix)
    {
        int m = matrix.size(), n = matrix[0].size();
        bool colZ = false, rowZ = false;
        for (int i = 0;i < m;++i)
        {
            for (int j = 0;j < n;++j)
            {
                if (matrix[i][j] == 0)
                {
                    matrix[i][0] = 0;
                    if (i == 0)colZ = true;
                    matrix[0][j] = 0;
                    if (j == 0)rowZ = true;
                }
            }
        }
        // for(int i=0;i<m;++i)
        // {
        //     for(int j=0;j<n;++j)
        //     {
        //         cout<<matrix[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        for (int i = 1;i < m;++i)
        {
            if (matrix[i][0] == 0)
            {
                for (int j = 0;j < n;++j)
                {
                    matrix[i][j] = 0;
                }
            }
        }
        for (int j = 1;j < n;++j)
        {
            if (matrix[0][j] == 0)
            {
                for (int i = 0;i < m;++i)
                {
                    matrix[i][j] = 0;
                }
            }
        }
        if (matrix[0][0] == 0)
        {
            if (colZ)
            {
                for (int j = 0;j < n;++j)
                {
                    matrix[0][j] = 0;
                }
            }
            if (rowZ)
            {
                for (int i = 0;i < m;++i)
                {
                    matrix[i][0] = 0;
                }
            }
        }
    }
};